<!--
 * @version: 
 * @Company: 
 * @Description: 
 * @FilePath: \src\views\tool\tpl\modal\diff\index.vue
-->
<template>
  <BasicModal v-bind="$attrs" @register="registerModal" title="代码对比" width="70%" :keyboard="false" :maskClosable="false" @cancel="visible = false" @ok="handleSubmit">
    <monaco-editor v-if="visible" v-model="modelValue" :diff="diffValue" />
  </BasicModal>
</template>
<script lang="ts">
  import { defineComponent, ref, nextTick } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import monacoEditor from '/@/components/Custom/MonacoEditor/index.vue';
  import * as _API from '../../api';
  export default defineComponent({
    name: 'diffEditor',
    components: { BasicModal, monacoEditor },
    emits: ['success'],
    setup(_, { emit }) {
      const visible = ref(false);
      const modelValue = ref(null); // 当前代码
      const diffValue = ref(null); // 需对比的旧代码
      const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
        diffValue.value = data.diffValue;
        modelValue.value = data.modelValue;
        nextTick(() => (visible.value = true));
        setModalProps({ confirmLoading: false });
      });
      const handleSubmit = () => {
        nextTick(() => (visible.value = false));
        closeModal();
        emit('success');
      };
      return { registerModal, visible, modelValue, diffValue, handleSubmit };
    },
  });
</script>
